//
//  PlacementVC.m
//  JAGatherAdDemo
//
//  Created by Yc on 2022/8/1.
//

#import "PlacementVC.h"
#import "Masonry.h"
#import "Header.h"

@interface PlacementVC ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic, strong) UITableView *tableView;

@end

@implementation PlacementVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"广告位";
    self.view.backgroundColor = [UIColor whiteColor];
    [self.tableView reloadData];
}

#pragma mark - 数据源方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataList.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    PlacementCell *cell = [tableView dequeueReusableCellWithIdentifier:@"PlacementCell"];
    if (!cell) {
        cell = [[PlacementCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"PlacementCell"];
    }
    // 设置 Cell...
    cell.contentView.backgroundColor = [UIColor whiteColor];
    cell.placementLabel.text = self.dataList[indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (self.TapCell) {
        self.TapCell(self.dataList[indexPath.row]);
    }
    
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - Layz
- (UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.backgroundColor = [UIColor whiteColor];
        [_tableView registerClass:[PlacementCell class] forCellReuseIdentifier:@"PlacementCell"];
        [self.view addSubview:_tableView];
    }
    return _tableView;
}

@end



@implementation PlacementCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self initUI];
    }
    return self;
}

- (void)initUI {
    self.placementLabel = [[UILabel alloc] init];
    self.placementLabel.font = [UIFont systemFontOfSize:14];
    self.placementLabel.textColor = [UIColor darkGrayColor];
    self.placementLabel.numberOfLines = 0;
    [self.contentView addSubview:self.placementLabel];
    [self.placementLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView).insets(UIEdgeInsetsMake(10, 20, 10, 10));
    }];
}


@end
